package com.ruoyi.web.controller.biz;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.Result;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.page.TableSupport;
import com.ruoyi.common.valid.ValidInsertGroup;
import com.ruoyi.common.valid.ValidUpdateGroup;
import com.ruoyi.system.domain.BsZhusu;
import com.ruoyi.system.service.BsZhusuService;
import io.swagger.annotations.*;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @ClassName BsZhusuController
 * @Author kenn
 * @Version 1.0.0
 * @Date 2023年10月17日 18:23:00
 */
@RestController
@RequestMapping("/bs/zhusu")
@Api(tags = "住宿管理")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class BsZhusuController extends BaseController {

    private final BsZhusuService zhusuService;

    @GetMapping("/page/list")
    @ApiOperation("分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name", value = "酒店/民宿名称"),
            @ApiImplicitParam(name = "pageNum", value = "分页参数：第几页"),
            @ApiImplicitParam(name = "pageSize", value = "分页参数：每页条数"),
    })
    public Result<TableDataInfo<BsZhusu>> pageList(String name) {
        PageDomain pageDomain = TableSupport.getPageDomain();
        return Result.success(zhusuService.pageList(pageDomain, name));
    }

    @PostMapping("/save")
    @ApiOperation("新增")
    public Result<?> save(@Validated(value = {ValidInsertGroup.class}) @RequestBody BsZhusu zhusu) {
        boolean save = zhusuService.saveEntity(zhusu);
        return save ? Result.success("新增成功") : Result.error("新增失败");
    }

    @PutMapping("/update")
    @ApiOperation("编辑")
    public Result<?> update(@Validated(value = {ValidUpdateGroup.class}) @RequestBody BsZhusu zhusu) {
        boolean save = zhusuService.updateEntity(zhusu);
        return save ? Result.success("编辑成功") : Result.error("编辑失败");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation("删除")
    public Result<?> delete(@ApiParam("主键id") @PathVariable("id") Long id) {
        boolean remove = zhusuService.delete(id);
        return remove ? Result.success("删除成功") : Result.error("删除失败");
    }

    @GetMapping("/export")
    @ApiOperation("导出")
    public AjaxResult<?> export() {
        return zhusuService.export();
    }

}
